from collections import defaultdict
import math

buy_order = {
    "2446.74": 0.461,
    "2446.62": 0.494,
    "2446.61": 0.012,
    "2446.55": 2.137,
    "2446.51": 5.341,
    "2446.5": 14.551,
    "2446.48": 0.012,
    "2446.46": 4.134,
    "2446.45": 2.606,
    "2446.44": 0.009
}

# 创建一个默认字典用于存储分组后的数据
grouped_buy_order = defaultdict(float)

for price, quantity in buy_order.items():
    # 将价格转换为 float 并四舍五入到最近的 0.1 单位
    rounded_price = round(float(price) * 10) / 10
    # 将相同价格区间的数量相加
    grouped_buy_order[rounded_price] += quantity

# 将 defaultdict 转换为普通字典并打印结果
grouped_buy_order = dict(grouped_buy_order)

for price, quantity in sorted(grouped_buy_order.items()):
    print(f"Price: {price}, Quantity: {quantity}")